package com.zbkj.crmeb.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.common.CommonPage;
import com.common.PageParamRequest;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.zbkj.crmeb.user.dao.UserInviteRewardDao;
import com.zbkj.crmeb.user.dao.UserRelRecordDao;
import com.zbkj.crmeb.user.model.UserInviteReward;
import com.zbkj.crmeb.user.model.UserRelRecord;
import com.zbkj.crmeb.user.service.UserInviteRewardService;
import com.zbkj.crmeb.user.service.UserRelRecordService;

import java.util.List;
import javax.annotation.Resource;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UserInviteRewardServiceImpl extends ServiceImpl<UserInviteRewardDao, UserInviteReward> implements UserInviteRewardService {

    @Resource
    private UserInviteRewardDao dao;

    @Override
    public UserInviteReward getByUserId(Integer userId) {
        LambdaQueryWrapper<UserInviteReward> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserInviteReward::getUserId, userId);
        return dao.selectOne(wrapper);
    }

    @Override
    public List<UserInviteReward> findByUserId(Integer userId) {
        LambdaQueryWrapper<UserInviteReward> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserInviteReward::getUserId, userId);
        return dao.selectList(wrapper);
    }

    @Override
    public List<UserInviteReward> findPage(Integer userId, PageParamRequest pageParamRequest) {
        LambdaQueryWrapper<UserInviteReward> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserInviteReward::getUserId, userId);
        return dao.selectList(wrapper);
    }

    @Override
    public PageInfo<UserInviteReward> getList(UserInviteReward request, PageParamRequest pageParamRequest) {
        Page<UserInviteReward> pageUser = PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        LambdaQueryWrapper<UserInviteReward> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (request.getMonthId() != null) {
            lambdaQueryWrapper.eq(UserInviteReward::getMonthId, request.getMonthId());
        }
        lambdaQueryWrapper.orderByDesc(UserInviteReward::getCreateTime);
        List<UserInviteReward> datas = dao.selectList(lambdaQueryWrapper);
        return CommonPage.copyPageInfo(pageUser, datas);
    }

    @Override
    public List<UserInviteReward> findByMonthIds(List<Integer> monthIds) {
        LambdaQueryWrapper<UserInviteReward> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(UserInviteReward::getMonthId, monthIds);
        return dao.selectList(wrapper);
    }
}
